<?php
namespace My\Model;

class ProductCategoryModel extends CommonTreeModel {
	
	// 插入成功后的回调方法
	protected function _after_insert($data, $options) {
		/*设置路径*/
		$newId = $data['id'];
		$pid = $data['pid']*1;
		$path = "$pid";
		while( $pid != 0 ) {
			$productCategory = M("ProductCategory")->where('id=%d', $pid)->find();
			$pid = $productCategory['pid']*1;
			$path = $pid.",{$path}";
		}
		$path.=",$newId";
		M("ProductCategory")->where('id=%d', $newId)->setField('path', $path);
	}
	
}